package com.unusap.remote.core.remote.hessian;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

import com.caucho.hessian.client.HessianProxyFactory;
import com.unusap.remote.core.remote.factory.HttpHeadersProvider;
import com.unusap.remote.core.remote.http.CommonHttpConnectionArguments;
import com.unusap.remote.core.util.URLConnectionPropertyUtils;

/**
 * Created by IntelliJ IDEA.
 * User: danson
 * Date: 2009-8-21
 * Time: 10:00:18
 * To change this template use File | Settings | File Templates.
 */
public class HttpHeaderSupportHessianProxyFactory extends HessianProxyFactory {

	private CommonHttpConnectionArguments connectionArguments = new CommonHttpConnectionArguments();

    private HttpHeadersProvider httpHeadersProvider;

    public HttpHeaderSupportHessianProxyFactory(HttpHeadersProvider httpHeadersProvider) {
        this.httpHeadersProvider = httpHeadersProvider;
    }

    @Override
    protected URLConnection openConnection(URL url) throws IOException {
        URLConnection urlConnection = super.openConnection(url);
        URLConnectionPropertyUtils.setProperty(urlConnection, httpHeadersProvider, connectionArguments);
        return urlConnection;
    }

    public void setConnectTimeout(int connectTimeout) {
    	connectionArguments.setConnectTimeout(connectTimeout);
    }

    @Override
    public void setUser(String sUser) {
    	connectionArguments.setUser(sUser);
    }

    @Override
    public void setPassword(String sPassword) {
    	connectionArguments.setPassword(sPassword);
    }
}
